﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDI窗体_Menustrip_Toolstrip
{
    public partial class Form1 : Form
    {
        Form frm2, frm3, frm4;

        public Form1()
        {
            InitializeComponent();

            this.IsMdiContainer = true;
        }

        private void 密码修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frm2 == null || frm2.IsDisposed) // 判断frm2是否为null或者是否被释放(关闭)
            {
                frm2 = new Form2();
                frm2.MdiParent = this;
                frm2.Show();
            }
            else
            {
                frm2.Activate();
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 弹出确认对话框
            DialogResult result = MessageBox.Show(
                "确定要退出吗？",
                "确认",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                Application.Exit(); // 正常退出，允许拦截
            }
        }

        private void 药品信息管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frm3 == null || frm3.IsDisposed) // 判断frm3是否为null或者是否被释放(关闭)
            {
                frm3 = new Form3();
                frm3.MdiParent = this;
                frm3.Show();
            }
            else
            {
                frm3.Activate();
            }
        }

        private void 药品采购计划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (frm4 == null || frm4.IsDisposed) // 判断frm4是否为null或者是否被释放(关闭)
            {
                frm4 = new Form4();
                frm4.MdiParent = this;
                frm4.Show();
            }
            else
            {
                frm4.Activate();
            }
        }
    }
}
